#coding=utf-8
import stockdb.misc as misc
import strategy.basic as basic

def bs_filter(td, n=3):
    
    tds = td.pre_n(n-1)
    if not tds:return False
    
    tds.insert(0, td)
    
    for t in tds:
        if t.b_s() < 0:return False
    
    return True

if __name__ == '__main__':

    date = '2008-06-17'
    #date = misc.today
    n = 3
    print date
    tds = misc.find_tds_on(date)
    print len(tds)
    tf = basic.TDFilter(tds)
    
    tds = tf.filter_by(basic.tdattr_filter, 'change', -8, 8).\
             filter_by(basic.tdattr_filter, 'close', 5, 25).\
             filter_by(bs_filter, n).\
             all()
             
    for td in tds:
        s = td.fins
        print s.code, s.name, int(td.max_bmoney/10000)
